﻿@inherits BaseComponent

@if (Context.IsEditTable && Model?.Table?.EnableEdit == true)
{
    <div class="kui-edit" style="margin-right:10px;" @onclick="OnEditTool">
        <KIcon Icon="edit" Title="编辑工具条按钮" />
    </div>
}
@if (Model != null && Model.HasItem)
{
    var items = Model.Items.Where(i => i.Visible).ToList();
    <div class="ant-toolbar">
        @if (items.Count > Model.ShowCount)
        {
            for (int i = 0; i < Model.ShowCount - 1; i++)
            {
                var item = items[i];
                @RenderButton(item)
            }
            var more = GetDropdownModel(Language["Button.More"]);
            more.Items = items.Skip(Model.ShowCount - 1).ToList();
            <AntDropdown Context="Context" Model="more" />
        }
        else
        {
            foreach (var item in items)
            {
                @RenderButton(item)
            }
        }
    </div>
}

@code {
    private RenderFragment RenderButton(ActionInfo item)
    {
        var itemName = Language.GetString(item);
        if (item.Children != null && item.Children.Count > 0)
        {
            var model = GetDropdownModel(itemName);
            model.Items = item.Children;
            return @<AntDropdown Context="Context" Model="model" />;
        }
        else
        {
            return @<KButton Name="@itemName" Enabled="item.Enabled" Type="GetButtonType(item.Style)" Danger="GetButtonDanger(item.Style)" Icon="@item.Icon" Title="@item.Title" Badge="item.Badge" OnClick="e=>Model.OnItemClick?.Invoke(item)" />;
        }
    }
}